package com.ateam.dao.impl;

import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;

import com.ateam.dao.ApplicationsDao;
import com.ateam.pojo.Applications;

/** 
* @author WuYuan
* 
*/
public class ApplicationsDaoImpl implements ApplicationsDao {
	private SqlSessionTemplate sqlSessionTemplate;
	
	public SqlSessionTemplate getSqlSessionTemplate() {
		return sqlSessionTemplate;
	}

	public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
		this.sqlSessionTemplate = sqlSessionTemplate;
	}
	
	@Override
	public int addApplication(Applications application) throws Exception {
		return sqlSessionTemplate.insert("addApplication", application);
	}

	@Override
	public int updateApplication(int applicationid) throws Exception {
		return sqlSessionTemplate.update("updateApplication", applicationid);
	}

	@Override
	public int addUserApplication(int applicant, int approver, int applicationid) throws Exception {
		Object[] objects = new Object[]{applicant,approver,applicationid};
		return sqlSessionTemplate.insert("addUserApplication", objects);
	}

	@Override
	public List<Applications> getApplicationsByApprover(int approver) throws Exception {
		return sqlSessionTemplate.selectList("getApplicationsByApprover", approver);
	}

	@Override
	public List<Applications> getApplicationsByApplicant(int applicant) throws Exception {
		return sqlSessionTemplate.selectList("getApplicationsByApplicant", applicant);
	}

}
